<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="utf-8">
  <title>设置我的资料</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <th:block th:include="common.html :: source"></th:block>
  <link href="/static/layui/css/layui.css" rel="stylesheet">
  <link href="/static/layui/css/layuiAdmin.css" rel="stylesheet">
  <link rel="stylesheet" href="/static/css/fileinput.min.css"></link>
  <script type="text/javascript" src="/static/js/fileinput.js"></script>
  <!-- 对中文的支持 -->
  <script type="text/javascript" src="/static/js/fileinput_locale_zh.js"></script>
</head>
<style>
  .layui-col-space15>* {
    padding: 15px;
  }
  .layui-form-label{
    width: 100px;
  }
  .layui-input-block{
    margin-left: 100px;
  }
</style>
<body>

<div class="layui-fluid">
  <div class="layui-row layui-col-space15">
    <div class="layui-col-md12">
      <div class="layui-card">
        <div class="layui-card-header">设置我的资料</div>
        <div class="layui-card-body" pad15>

          <div class="layui-form" lay-filter="">
            <div class="layui-form-item">
              <label class="layui-form-label">我的角色</label>
              <div class="layui-input-inline">
                <select name="role" lay-verify="">
                  <option value="1" selected>超级管理员</option>
                  <option value="2" disabled>普通管理员</option>
                  <option value="3" disabled>审核员</option>
                  <option value="4" disabled>编辑人员</option>
                </select>
                <input type="hidden" id="id" name="id" th:value="${session.loginInfo.id}">
                <input type="hidden" id="root" name="root" th:value="${session.loginInfo.root}">
              </div>
              <div class="layui-form-mid layui-word-aux">当前角色不可更改为其它角色</div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">用户名</label>
              <div class="layui-input-inline">
                <input type="text" name="username" style="margin-left: 0" id="username" th:value="${session.loginInfo.username}" readonly class="layui-input">
              </div>
              <input type="hidden" id="password" name="password" th:value="${session.loginInfo.password}">
              <input type="hidden" id="adminId" name="adminId" th:value="${session.loginInfo.adminId}">
              <div class="layui-form-mid layui-word-aux">不可修改。一般用于后台登入名</div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">昵称</label>
              <div class="layui-input-inline">
                <input type="text" name="nickname" id="nickname" th:value="${session.loginInfo.nickname}" lay-verify="nickname" autocomplete="off" placeholder="请输入昵称" class="layui-input">
              </div>
            </div>

<!--            <div class="layui-form-item" >-->
<!--              <label class="layui-form-label">头像</label>-->
<!--              <div class="layui-input-inline">-->
<!--                <input name="headPortrait" lay-verify="required" id="LAY_avatarSrc" placeholder="图片地址" th:value="${session.loginInfo.headPortrait}" class="layui-input">-->
<!--              -->
<!--              </div>-->
<!--              <div class="layui-input-inline layui-btn-container" style="width: auto;">-->
<!--                <button type="button" class="layui-btn layui-btn-primary" id="LAY_avatarUpload">-->
<!--                  <i class="layui-icon">&#xe67c;</i>上传图片-->
<!--                </button>-->
<!--              </div>-->
<!--            </div>-->
            <div class="layui-form-item" >
              <label class="layui-form-label">头像</label>
              <div class="layui-input-inline">
                <input type="text" name="headPortrait" id="LAY_avatarSrc" th:value="${session.loginInfo.headPortrait}"/>
<!--                <input name="headPortrait" lay-verify="required" id="LAY_avatarSrc" placeholder="图片地址" th:value="${session.loginInfo.headPortrait}" class="layui-input">-->

              </div>
              <form enctype="multipart/form-data">
                <input id="file-product" class="file" name="file" type="file" multiple
                       data-min-file-count="1">
              </form>
            </div>

            <div class="layui-form-item">
              <label class="layui-form-label">手机</label>
              <div class="layui-input-inline">
                <input type="text" name="phone" id="phone" th:value="${session.loginInfo.phone}" lay-verify="phone" autocomplete="off" class="layui-input">
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">邮箱</label>
              <div class="layui-input-inline">
                <input type="text" name="email" id="email" th:value="${session.loginInfo.email}" lay-verify="email" autocomplete="off" class="layui-input">
                <input type="hidden" name="sex" id="sex" th:value="${session.loginInfo.sex}">
                <input type="hidden" name="categoryType" id="categoryType" th:value="${session.loginInfo.categoryType}">
                <input type="hidden" name="creatTime" id="creatTime" th:value="${session.loginInfo.createTime}">
                <input type="hidden" name="updateTime" id="updateTime" th:value="${session.loginInfo.updateTime}">
              </div>
            </div>
            <div class="layui-form-item layui-form-text">
              <label class="layui-form-label">备注</label>
              <div class="layui-input-block">
                <textarea name="remarks" id="remarks" placeholder="请输入内容" class="layui-textarea" th:text="${session.loginInfo.remarks}"></textarea>
              </div>
            </div>
            <div class="layui-form-item">
              <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="setmyinfo">确认修改</button>
                <button type="reset" class="layui-btn layui-btn-primary">重新填写</button>
              </div>
            </div>
          </div>

        </div>
      </div>
    </div>
  </div>
</div>

<script src="/static/layui/layui.js" charset="UTF-8"></script>
<script>

  layui.use('upload', function(){
    var upload = layui.upload;

    //执行实例
    var uploadInst = upload.render({
      elem: '#LAY_avatarUpload' //绑定元素
      ,url: '/manage/upload' //上传接口
      ,data: {
        id: function () {
          return $('#id').val();
        }
      }
      ,accept: 'images'
      ,size: 1000
      ,done: function(res){
        //上传完毕回调
        document.getElementById("LAY_avatarSrc").value=res.data;
      }
      ,error: function(){
        //请求异常回调
      }
    });
  });

  layui.use(['layer', 'form'], function () {
    var layer = layui.layer;
    var form = layui.form;
    form.on('submit()', function () {
      $.post({
        url: '/manage/updatePersonInfo',
        data: {
          "id": $("#id").val(),
          "adminId": $("#adminId").val(),
          "username": $("#username").val(),
          "password": $("#password").val(),
          "email": $("#email").val(),
          "phone": $("#phone").val(),
          "nickname": $("#nickname").val(),
          "remarks": $("#remarks").val(),
          "root": $("#root").val(),
          "categoryType": $("#categoryType").val(),
          "sex": $("#sex").val(),
          "headPortrait": $("#LAY_avatarSrc").val(),
          "createTime": $("#createTime").val(),
          "updateTime": $("#updateTime").val(),
        },
        success: function (data) {
          if (data === "true") {
            layer.msg('修改成功！', {icon: 6, offset: "auto", time: 2000});//提示框
          } else {
            layer.msg('修改失败！', {icon: 5, offset: "auto", time: 2000});//提示框
          }
          setTimeout(function () {
            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);//关闭弹出层
            parent.location.reload();//重新加载父页面表格
          }, 2100);
        }
      });
      return false;
    });
  });



  //===============图片上传==============================
  /**
   * 初始设置
   *   language指定语言
   *   uploadUrl指定文件上传的后台地址
   *   allowedPreviewTypes允许上传文件的类型
   */
  $('#file-product').fileinput({
    language: 'zh',
    uploadUrl: '${ctx}/fileUpload/save',
    allowedPreviewTypes: ['image', 'html', 'text', 'video', 'audio', 'flash']
  });
  /**
   * 上传文件失败后 调用方法（回调函数）
   */
  $('#file-product').on('fileuploaderror', function (event, data, previewId, index) {
    var form = data.form,
            files = data.files,
            extra = data.extra,
            response = data.response,
            reader = data.reader;
    console.log(data);
    console.log('File upload error');
  });
  /**
   * 文件错误 比如文件类型错误 调用方法（回调函数）
   */
  $('#file-product').on('fileerror', function (event, data) {
    console.log(data.id);
    console.log(data.index);
    console.log(data.file);
    console.log(data.reader);
    console.log(data.files);
  });
  /**
   * 文件上传成功后 调用方法（回调函数）
   */
  $('#file-product').on('fileuploaded', function (event, data, previewId, index) {
    var form = data.form,
            files = data.files,
            extra = data.extra,
            response = data.response,
            reader = data.reader;
    // 服务器文件地址
    // alert(data.response.fileUrl);
    // 将服务器文件地址设置至隐藏域
    $("#originalImg").val(data.response.fileUrl);
    console.log('File uploaded triggered');
  });
</script>
</body>
</html>